package com.lin.cms.validator;

import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

import com.lin.cms.domain.ModelItem;

public class ModelItemValidator implements Validator {

	@SuppressWarnings("unchecked")
	public boolean supports(Class clazz) {
		return ModelItem.class.isAssignableFrom(clazz);
	}

	public void validate(Object target, Errors errors) {
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "modelitemId", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "modelId", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "field", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "itemLabel", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "priority", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "dataType", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "isSingle", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "isChannel", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "isCustom", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "isDisplay", "required");
	}

}
